<?php

namespace haibao\app\data;

class Area extends \haibao\app\data\BaseMysql{

	public function __construct(){
		parent::__construct('\haibao\app\model\data\Area');
	}
	
	/**
	 * 查询是否存在所有地区(display=1)的缓存
	 */
	public function getAllArea(){
		$cache = new \haibao\app\cache\Column();
		$areaList = json_decode($cache->getCacheByKey(\haibao\app\model\data\Area::CACHE_AREA_KEY),true);
		if(empty($areaList)){
			$areaList = $this->setAreaCache();
		}
		return $areaList;
	}
	
	private  function setAreaCache(){
		$areaList = array();
		$sql = "select * from Area where Display=1 ";
		$result = $this->query($sql);
		$list = array();
		while ($result->fetch_assoc()){
			$list['Id'] = $result->getData('Id');
			$list['Name'] = $result->getData('Name');
			$areaList[] = $list;
		}
		$cache = new \haibao\app\cache\Column();
		$cache->setCache(\haibao\app\model\data\Area::CACHE_AREA_KEY, json_encode($areaList,true));
		return $areaList;
	}
}